import { RbacRoleType } from '@/datatypes/rbacRole/data';
import { list } from '@/services';
import { rbacRoleUrl } from '@/urls';
import { useEffect, useState } from 'react';

export const useRoles = () => {
  const [roles, setRoles] = useState<RbacRoleType[]>([]);

  useEffect(() => {
    const fetchRolesData = async () => {
      const data: API.ListResult<RbacRoleType> = await list(rbacRoleUrl);
      setRoles(data?.list || []);
    };

    fetchRolesData();
  }, []);

  return roles;
};
